<template>
  <el-row :gutter="20">
    <el-col :span="18">
      <el-card>
        <div class="title">
          <h3>今日设备运行状态</h3>
          <p class="ml">更新时间:2024年8月31日</p>
          <el-icon color="#86909c" style="margin-left: 5px">
            <Refresh />
          </el-icon>
        </div>
        <div class="equipment">
          <div class="item" v-for="item in equipment" :key="item.id">
            <div class="item-top">{{ item.name }}</div>
            <img :src="item.flash" alt="" />
            <div class="number">{{ item.number }}</div>
            <div class="mini-text">
              <span>异常设备</span><el-icon><WarningFilled /></el-icon>
            </div>
            <div class="mini_number">{{ item.mini_number }}</div>
            <div>
              相较昨日 {{ item.compare }}
              <el-icon :color="item.iconColor">
                <component :is="item.iconComponent" />
              </el-icon>
            </div>
          </div>
        </div>
      </el-card>
      <el-card class="mt">
        <template #header>
          <div class="card-header">
            <h1>常用功能</h1>
          </div>
        </template>
        <div class="modules">
          <div class="item" v-for="item in modules" :key="item.id">
            <img :src="item.img" alt="" />
            <span>{{ item.title }}</span>
          </div>
        </div>
      </el-card>
      <el-card class="mt">
        <template #header>
          <div class="card-header">
            <h1>能源统计</h1>
          </div>
        </template>
        <el-row>
          <el-col :span="6">
            <div ref="chartRef2" style="width: 100%; height: 400px"></div>
          </el-col>
          <el-col :span="18">
            <div ref="chartRef" style="width: 100%; height: 400px"></div>
          </el-col>
        </el-row>
      </el-card>
    </el-col>
    <el-col :span="6">
      <el-card>
        <div>做</div>
      </el-card>
    </el-col>
  </el-row>
</template>

<script setup lang="ts">
import { ref } from "vue";
import flash from "@/assets/flash.png";
import flash2 from "@/assets/flash2.png";
import flash3 from "@/assets/flash3.png";
import repair from "@/assets/repair.png";
import daily from "@/assets/daily.png";
import progress from "@/assets/progress.png";
import total from "@/assets/total.png";
import money from "@/assets/money.png";
import remain from "@/assets/remain.png";
import { useChart } from "@/hooks/useChart";
import { chartDataApi } from "@/api/dashboard";
const equipment = ref([
  {
    id: 1,
    name: "充电桩使用率",
    number: "2263 / 3398",
    mini_number: "9",
    compare: "16%",
    icon: "CaretTop",
    iconColor: "green",
    iconComponent: "CaretTop",
    flash: flash,
  },
  {
    id: 2,
    name: "充电桩使用率",
    number: "3263 / 4008",
    mini_number: "4",
    compare: "33%",
    icon: "CaretTop",
    iconColor: "red",
    iconComponent: "CaretBottom",
    flash: flash2,
  },

  {
    id: 3,
    name: "充电桩使用率",
    number: "1000 / 2367",
    mini_number: "7",
    compare: "24%",
    icon: "CaretTop",
    iconColor: "green",
    iconComponent: "CaretTop",
    flash: flash3,
  },
]);
const modules = ref([
  {
    id: 1,
    title: "设备维修",
    img: repair,
  },
  {
    id: 2,
    title: "每日日报",
    img: daily,
  },
  {
    id: 3,
    title: "任务进度",
    img: progress,
  },
  {
    id: 4,
    title: "营收占比",
    img: total,
  },
  {
    id: 5,
    title: "营收统计",
    img: money,
  },
  {
    id: 6,
    title: "代办事项",
    img: remain,
  },
]);
const chartRef = ref(null);
const chartOptions = {
  title: {
    text: "电量统计",
  },
  tooltip: {
    trigger: "axis",
  },
  legend: {
    data: ["充电量", "充电时长", "充电功率"],
  },
  // grid: {
  //   left: "3%",
  //   right: "4%",
  //   bottom: "3%",
  //   containLabel: true,
  // },
  //显示保存图片图标
  // toolbox: {
  //   feature: {
  //     saveAsImage: {},
  //   },
  // },
  xAxis: {
    type: "category",
    boundaryGap: false,
    data: [
      "13:00",
      "14:00",
      "15:00",
      "16:00",
      "17:00",
      "18:00",
      "19:00",
      "20:00",
      "21:00",
    ],
  },
  yAxis: {
    type: "value",
    axisLabel: {
      formatter: "{value}kw", // 示例：添加百分比符号
    },
  },
  series: [
    {
      name: "充电量",
      type: "line",
      smooth: true,
      data: [120, 132, 101, 134, 90, 230, 210],
    },
    {
      name: "充电时长",
      type: "line",
      smooth: true,
      data: [220, 182, 191, 234, 290, 330, 310],
    },
    {
      name: "充电功率",
      type: "line",
      smooth: true,
      data: [150, 232, 201, 154, 190, 330, 410],
    },
  ],
};
useChart(chartRef, chartOptions);
const getData = async () => {
  let res = await chartDataApi();
  console.log(res, "res");
};
getData();
</script>

<style lang="less" scoped>
.title {
  display: flex;
  font-size: 20px;
  font-weight: bold;
  text-align: center;
  align-items: flex-end;
  margin-bottom: 20px;

  p {
    color: #86909c;
  }
}
.equipment {
  display: flex;
  padding: 0 50px;
  justify-content: space-between;
  .item {
    .item-top {
      font-size: 16px;
      color: #303133;
      font-weight: bold;
      margin: 20px 0;
    }
    img {
      margin: 20px 0;
    }
    .number {
      font-size: 36px;
      margin-bottom: 20px;
      font-weight: bold;
    }
    .mini-text {
      font-size: 12px;
      color: #606266;
      span {
        margin-right: 5px;
      }
    }
    .mini_number {
      font-size: 20px;
      margin: 10px 0;
    }
  }
}
.oftenTitle {
  font-size: 19px;
  font-weight: bold;
}
.modules {
  display: flex;
  justify-content: space-around;
  .item {
    img {
      margin-bottom: 10px;
    }
    display: flex;
    margin-bottom: 10px;
    flex-direction: column;
    justify-items: center;
  }
}
</style>
